﻿using System;
using System.Collections.Generic;
using System.Windows.Input;

namespace WholeSlideImageViewer
{
    internal class OptiOutputDialogViewModel : ViewModelBase, IOptiOutputOptions
    {
        private readonly TileSizeOption[] _tileSizeOptions;

        private TileSizeOption _tileSize;

        private bool _enableTiffCompatibility;

        private ICommand? _confirmCommand;
        private ICommand? _cancelCommand;

        public event Action<IOptiOutputOptions>? RequestConfirm;
        public event Action? RequestCancel;

        public IEnumerable<TileSizeOption> TileSizeOptions => _tileSizeOptions;

        public TileSizeOption TileSize { get => _tileSize; set => OnPropertyChanged(nameof(TileSize), ref _tileSize, value); }

        int IOptiOutputOptions.TileSize => _tileSize.TileSise;

        public bool EnableTiffCompatibility { get => _enableTiffCompatibility; set => OnPropertyChanged(nameof(EnableTiffCompatibility), ref _enableTiffCompatibility, value); }

        public ICommand ConfirmCommand => _confirmCommand ??= new RelayCommand(_ => Confirm(), _ => true);

        public ICommand CancelCommand => _cancelCommand ??= new RelayCommand(_ => Cancel(), _ => true);

        public OptiOutputDialogViewModel()
        {
            _tileSizeOptions = new TileSizeOption[]
           {
                new TileSizeOption(64, "64"),
                new TileSizeOption(128, "128"),
                new TileSizeOption(256, "256 (推荐)"),
                new TileSizeOption(512, "512"),
                new TileSizeOption(1024, "1024"),
           };
            _tileSize = _tileSizeOptions[2]; // 256

            _enableTiffCompatibility = true;
        }

        public void Confirm()
        {
            RequestConfirm?.Invoke(this);
        }

        public void Cancel()
        {
            RequestCancel?.Invoke();
        }

        public class TileSizeOption
        {
            public TileSizeOption(int tileSise, string displayText)
            {
                TileSise = tileSise;
                DisplayText = displayText;
            }

            public int TileSise { get; set; }
            public string? DisplayText { get; set; }
        }

    }
}
